package com.yoomiito.app.ui.my.remain.withdraw

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.text.Html
import android.text.TextUtils
import com.yoomiito.app.R
import com.yoomiito.app.base.App
import com.yoomiito.app.base.BaseActivity
import com.yoomiito.app.model.bean.UserInfo
import com.yoomiito.app.model.my.ApplyInfo
import com.yoomiito.app.model.my.MyUserCenterInfo
import com.yoomiito.app.utils.YMToast
import kotlinx.android.synthetic.main.activity_add_withdraw.btn_submit
import kotlinx.android.synthetic.main.activity_withdraw.et_money
import kotlinx.android.synthetic.main.activity_withdraw.iv_type
import kotlinx.android.synthetic.main.activity_withdraw.tv_accopunt
import kotlinx.android.synthetic.main.activity_withdraw.tv_account1
import kotlinx.android.synthetic.main.activity_withdraw.tv_remark
import kotlinx.android.synthetic.main.title_bar.iv_back_left
import kotlinx.android.synthetic.main.title_bar.tv_center

/**
 */
class WithdrawActivity : BaseActivity<WithdrawPresenter>() {
    private var applyInfo: ApplyInfo? = null
    private var type : Int = 1
    companion object {
        fun start(context: Context, applyInfo: ApplyInfo,type:Int) {
            val intent = Intent(context, WithdrawActivity::class.java)
            intent.putExtra("applyInfo", applyInfo)
            intent.putExtra("type", type)

            context.startActivity(intent)
        }
    }

    override fun getLayoutId(): Int = R.layout.activity_withdraw

    override fun newP(): WithdrawPresenter = WithdrawPresenter(App.mAppConfig)


    override fun initData(savedInstanceState: Bundle?) {
        initView()
        p.withdrawalMsg()
        p.getUserCenterData()
    }

    private fun initView() {
        iv_back_left.setOnClickListener { finish() }
        tv_center.text = "提现"
        type = intent.getIntExtra("type",1)
        applyInfo = intent.getSerializableExtra("applyInfo") as ApplyInfo
        if (applyInfo?.id?.isEmpty() == false) {
            if (applyInfo?.type == 1) {
                iv_type.setImageResource(R.drawable.order_wechat)
            } else {
                iv_type.setImageResource(R.drawable.order_zfb)
            }
            tv_accopunt.text = applyInfo?.userName
        }
        btn_submit.setOnClickListener {
            val money = et_money.text.toString()
            if(TextUtils.isEmpty(money)){
                YMToast.showText("提现金额不能为空")
                return@setOnClickListener
            }
            applyInfo?.id?.let { it1 -> p.withdrawApply(it1,money, type) }
        }
    }


    override fun setUserInfo(userInfo: UserInfo?) {
        super.setUserInfo(userInfo)

    }

    fun setData(msg: String) {

        tv_remark.text = Html.fromHtml(msg)
    }

    fun setData1(msg: MyUserCenterInfo) {
        if(type ==1){
            tv_account1.text = "当前余额  ¥${msg.money}"
        }else{
            tv_account1.text = "当前余额  ¥${msg.mugwordMoney}"
        }

    }

}